package kit.edu.lego.gruppe3.levels.treeArea.entrance;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.LegoMain;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.treeArea.TreeAreaSolver;
import lejos.nxt.LightSensor;
import lejos.nxt.NXTRegulatedMotor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.subsumption.Behavior;

public class EntranceEndReached implements Behavior{
	
	private LightSensor lightS = ComponentsRepository.getInstance().getLightSensor();
	private DifferentialPilot robot = ComponentsRepository.getInstance().getRobotPilot();
	private NXTRegulatedMotor motor = ComponentsRepository.getInstance().getMiddleMotor();

	@Override
	public void action() {
		motor.rotate(-30);
		robot.travel(7.0f);
		ComponentsRepository.getInstance().getMiddleMotor().flt();
		TreeAreaSolver.setLevelCleared(true);
		LegoMain.startBridge();
	}

	@Override
	public void suppress()
	{

	}

	@Override
	public boolean takeControl()
	{
		return LevelSelector.getInstance().isTreeArea() &&
			TreeAreaSolver.objectFound &&
			lightS.getLightValue() > ComponentsRepository.LIGHT_TRASHOLD;
	}

}
